package net.alteiar.ui.listener;

import java.awt.Point;
import java.awt.event.MouseEvent;

import net.alteiar.ui.MovablePanel;
import net.alteiar.ui.condition.DefaultCondition;
import net.alteiar.ui.condition.MouseCondition;

public class MoveListener extends ConditionMouseAdapter {
	private Point first;

	private final MovablePanel movable;

	public MoveListener(MovablePanel movable) {
		this(new DefaultCondition(), movable);
	}

	public MoveListener(MouseCondition condition, MovablePanel movable) {
		super(condition);
		this.movable = movable;
	}

	@Override
	protected void realMousePressed(MouseEvent e) {
		first = e.getPoint();
	}

	@Override
	protected void realMouseDragged(MouseEvent e) {
		if (first != null) {
			int moveX = first.x - e.getPoint().x;
			int moveY = first.y - e.getPoint().y;
			movable.moveInside(moveX, moveY);
		}
	}
}
